/*     */ package com.qmsk.session;
/*     */ 
/*     */ import com.qmsk.session.bean.CSessionUser;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class UserSessionInfo
/*     */ {
/*     */   private static final String USER_SESSION_INFO = "USER_SESSION_INFO";
/*     */   private static final String DOUBLE_USER_ONLINE = "DOUBLE_USER_ONLINE";
/*  23 */   private static final Logger logger = Logger.getLogger(UserSessionInfo.class);
/*     */ 
/*     */   private static void httpSession_removeAttr(HttpSession session)
/*     */   {
/*  27 */     httpSession_destroy(session, false);
/*     */   }
/*     */ 
/*     */   private static void httpSession_destroy(HttpSession session, boolean bInvalid)
/*     */   {
/*  32 */     if (session == null) return;
/*     */     try {
/*  34 */       if (bInvalid) {
/*  35 */         session.invalidate();
/*  36 */         return; }
/*  37 */       session.removeAttribute("USER_SESSION_INFO");
/*  38 */       session.setAttribute("USER_SESSION_INFO", null);
/*     */ 
/*  40 */       session.removeAttribute("DOUBLE_USER_ONLINE");
/*  41 */       session.setAttribute("DOUBLE_USER_ONLINE", null);
/*     */     }
/*     */     catch (Exception e) {
/*  44 */       logger.error(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public static void request_logout(HttpServletRequest request)
/*     */   {
/*  56 */     httpSession_destroy(request.getSession(false), true);
/*     */   }
/*     */ 
/*     */   public static boolean request_login(HttpServletRequest request, CSessionUser u)
/*     */   {
/*  62 */     HttpSession session = request.getSession(false);
/*     */ 
/*  64 */     if (session == null) {
/*  65 */       session = request.getSession(true);
/*     */     }
/*     */ 
/*  68 */     if (session != null) {
/*  69 */       boolean bReturn = false;
/*     */ 
/*  71 */       HttpSession session_old = UserSessionListener.addUser(u.getUserId(), session);
/*  72 */       if ((session_old != null) && (session_old != session)) {
/*  73 */         httpSession_removeAttr(session_old);
/*  74 */         session_setAttributeObject(session_old, "DOUBLE_USER_ONLINE", new Integer(1));
/*  75 */         bReturn = true;
/*     */       }
/*     */ 
/*  78 */       httpSession_removeAttr(session);
/*     */ 
/*  80 */       session_setAttributeObject(session, "USER_SESSION_INFO", u);
/*  81 */       return bReturn;
/*     */     }
/*  83 */     return false;
/*     */   }
/*     */ 
/*     */   public static CSessionUser user_getUserOfRequest(HttpServletRequest request)
/*     */   {
/*  89 */     return user_getUserOfHttpSession(request.getSession(false));
/*     */   }
/*     */ 
/*     */   private static Object session_getAttributeObject(HttpSession session, String key) {
/*     */     try {
/*  94 */       if (session != null)
/*  95 */         return session.getAttribute(key);
/*  96 */       return null;
/*     */     } catch (Exception e) {
/*  98 */       logger.error(e); }
/*  99 */     return null;
/*     */   }
/*     */ 
/*     */   private static void session_setAttributeObject(HttpSession session, String key, Object o)
/*     */   {
/*     */     try {
/* 105 */       if (session != null)
/* 106 */         session.setAttribute(key, o);
/*     */     }
/*     */     catch (Exception e) {
/* 109 */       logger.error(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   private static Integer user_getDoubleOnLineOfHttpSession(HttpSession session)
/*     */   {
/* 115 */     if (session != null) {
/* 116 */       return ((Integer)session_getAttributeObject(session, "DOUBLE_USER_ONLINE"));
/*     */     }
/* 118 */     return null;
/*     */   }
/*     */ 
/*     */   public static Integer user_getDoubleOnLineOfRequest(HttpServletRequest request)
/*     */   {
/* 124 */     return user_getDoubleOnLineOfHttpSession(request.getSession(false));
/*     */   }
/*     */ 
/*     */   public static CSessionUser user_getUserOfHttpSession(HttpSession session)
/*     */   {
/* 129 */     if (session != null) {
/* 130 */       return ((CSessionUser)session_getAttributeObject(session, "USER_SESSION_INFO"));
/*     */     }
/* 132 */     return null;
/*     */   }
/*     */ 
/*     */   public static boolean user_isLoginOfHttpSession(HttpSession session)
/*     */   {
/* 138 */     CSessionUser u = user_getUserOfHttpSession(session);
/*     */ 
/* 140 */     return (u != null);
/*     */   }
/*     */ 
/*     */   public static boolean user_isDoubleOnLineOfHttpSession(HttpSession session)
/*     */   {
/* 148 */     Integer n = user_getDoubleOnLineOfHttpSession(session);
/*     */ 
/* 150 */     return (n != null);
/*     */   }
/*     */ 
/*     */   public static String user_getUserIdOfHttpSession(HttpSession session)
/*     */   {
/* 158 */     CSessionUser u = user_getUserOfHttpSession(session);
/* 159 */     if (u != null) {
/* 160 */       return u.getUserId();
/*     */     }
/* 162 */     return "";
/*     */   }
/*     */ 
/*     */   public static String user_getUserNameOfHttpSession(HttpSession session)
/*     */   {
/* 168 */     CSessionUser u = user_getUserOfHttpSession(session);
/* 169 */     if (u != null) {
/* 170 */       return u.getUserName();
/*     */     }
/* 172 */     return "";
/*     */   }
/*     */ 
/*     */   public static String getUserIdOfSession(HttpServletRequest request)
/*     */   {
/* 177 */     HttpSession session = request.getSession(false);
/* 178 */     return user_getUserIdOfHttpSession(session);
/*     */   }
/*     */ 
/*     */   public static Long getIntUserIdOfRequest(HttpServletRequest request) {
/* 182 */     HttpSession session = request.getSession(false);
/* 183 */     String s = user_getUserIdOfHttpSession(session);
/* 184 */     if (s == null) {
/* 185 */       return Long.valueOf(0L);
/*     */     }
/* 187 */     return Long.valueOf(s);
/*     */   }
/*     */ 
/*     */   public static String getUserNameOfRequest(HttpServletRequest request)
/*     */   {
/* 192 */     HttpSession session = request.getSession(false);
/* 193 */     String s = user_getUserNameOfHttpSession(session);
/* 194 */     if (s == null) {
/* 195 */       return "";
/*     */     }
/* 197 */     return s;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.session.UserSessionInfo
 * JD-Core Version:    0.5.3
 */